package 算法;

public class 买卖股票的最佳时机 {
    public static void main(String[] args) {

    }
    //返回以第0个导入，的最优值
    public int maxProfit(int[] prices) {
        if(prices.length == 0){
            return 0;
        }
        int[][] res = new int[prices.length][2];
        res[0][0] = prices[0];
        res[0][1] = 0;
        for (int i = 1; i < prices.length; i++) {
            res[i][0] = Math.min(res[i-1][0],prices[i]);
            res[i][1] = Math.max(0,prices[i]-res[i-1][0]);
        }
        int co = 0;
        for (int i = 1; i < res.length; i++) {
            co = co > res[i][1] ? co:res[i][1];
        }
        return co;
    }
}
